package com.hsylient.aop.service;

import com.hsylient.aop.annotations.RetryOnException;
import com.hsylient.aop.entity.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Slf4j
@Service
public class OrderService {


    public Order findOrder() {
        Order order = new Order();
        order.setId(1001L);
        order.setCategory("小飞机");
        order.setAmount(BigDecimal.ONE);
        order.setPrice(BigDecimal.TEN);
        order.setCreateTime(LocalDateTime.now());
        order.setStatus(1);
        order.setUserId(20220110L);
        return order;
    }

    @RetryOnException(maxRetries = 6)
    public String testCustomerAnnotation(String param) {
        log.info("[测试自定义注解实现错误重试] 请求参数 {}", param);

        // 手动抛出来运行时异常，模拟方法执行报错
        throw new RuntimeException("throw Runtime Exception");
    }
}
